﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CmpEdu
{
    public partial class Frm10_2Reg : Form
    {
        public Frm10_2Reg()
        {
            InitializeComponent();
        }

        private void Frm10_2Reg_Load(object sender, EventArgs e)
        {
            this.Text = "注册新用户";
            CbLevel.Text = CbLevel.Items[0].ToString();
            TbName.Text = "admin";
            TbPwd.Text = "bushuang09";
            TbPwdRe.Text = "bushuang09";
            CbLevel.Enabled = false;
        }

        private void BtnCommit_Click(object sender, EventArgs e)
        {
            if (TbName.Text.Trim()=="" || TbPwd.Text.Trim()=="")
            {
                MessageBox.Show("用户名或密码不能为空！", "出错",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (TbPwd.Text.Trim().Length < 8)
            {
                MessageBox.Show("密码长度至少8位！", "出错",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (TbPwd.Text != TbPwdRe.Text)
            {
                MessageBox.Show("两次输入的密码不同！", "出错",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                string uname = TbName.Text;
                string upwd = TbPwd.Text;
                string ulevel = CbLevel.Text;
                string MsgInfo = UserManager.AddUser(uname,upwd,ulevel);
                MessageBox.Show(MsgInfo, "提示信息",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void BtnAbolish_Click(object sender, EventArgs e)
        {
            this.Close();
            FrmT10_2Login login = new FrmT10_2Login();
            login.Show();
        }
    }
}
